<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			function search(){
				// var $uid=uid.value;
			var urlParams=new URLSearchParams(location.search)
			var $uid=urlParams.get("uid");
				
				var xhr=new XMLHttpRequest();
				xhr.onreadystatechange=function(){
					if(xhr.readyState==4 && xhr.status==200){
						var r=xhr.responseText;
						 if(r==0){
							 alert("查无此人");
						 }else{
							 var arr=JSON.parse(r);
							 uname.value=arr[0].uname;
							 upwd.value=arr[0].upwd;
							 email.value=arr[0].email;
							 user_name.value=arr[0].user_name;
							 phone.value=arr[0].phone;
							 avatar.value=arr[0].avatar;
							// gender.value=arr[0].gender;
							if(arr[0].gender==1){
								man.checked=true;
							}else if(arr[0].gender==0){
								woman.checked=true;
							}else if(arr[0].gender==-1){
								unk.checked=true;
							}
						 }									
					}
				}
				xhr.open("get",'/pro1/v1/search/'+$uid,true);
				xhr.send();
			}
			
			
			
			
			function update(){
				var urlParams=new URLSearchParams(location.search)
				var $uid=urlParams.get("uid");
				//var $uid=uid.value;
				var $uname=uname.value;
				var $upwd=upwd.value;
				var $email=email.value;
				var $phone=phone.value;
				var $avatar=avatar.value;
				var $user_name=user_name.value;
			    var $gender= "-1";
				 if(man.checked){
					   $gender=man.value;
				}else if (woman.checked){
					   $gender=woman.value;
				}else{
				 	   $gender=unk.value;
				}
		
				/*
				if(!$uid){alert("请输入id");return}
				if(!$uname){alert("请输入用户名");return}
				if(!$upwd){alert("请输入密码");return}
				if(!$email){alert("请输入邮箱");return}
				if(!$gender){alert("请输入性别");return}
				if(!$phone){alert("请输入电话");return}*/
				var xhr=new XMLHttpRequest();
				xhr.onreadystatechange=function(){
					if(xhr.readyState==4 && xhr.status==200){
						var r=xhr.responseText;
						//d1.innerHTML=r;
						console.log(r);
					   if(r>0){
							 alert("修改成功")
							 location.href="http://127.0.0.1:8080/_v1list.html";
						 }else{
							 alert("修改失败")
						 }
						
					}
				}
				xhr.open("put","/pro1/v1/update",true);
				  var formdata=`uid=${$uid}&uname=${$uname}&upwd=${$upwd}&email=${$email}&phone=${$phone}&gender=${$gender}&avatar=${$avatar}&user_name=${$user_name}`;
					xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				xhr.send(formdata);
			}
				
			
			
		</script>
	</head>
	<body onload="search()">
		<!-- <input type="text" id="uid"><br> -->
		<!-- <button onclick="search()">登录</button> -->
		<div id="d1">
			账号<input type="text" id="uname"><br>
		  密码<input type="text" id="upwd"><br>
			邮箱<input type="text" id="email"><br>
			电话<input type="text" id="phone"><br>
			姓名<input type="text" id="user_name"><br>
			头像<input type="text" id="avatar"><br>
	<!-- <input type="text" id="gender"><br> -->
	    <input name="gender" type="radio" id="man" value="1"checked>男
			<input name="gender" type="radio" id="woman"value="0">女
			<input name="gender" type="radio" id="unk"  value="-1">	保密
			<br><button onclick="update()">修改</button>
		</div>
		
	</body>
</html>

</table>